package com.fh.modules.kms.controller;

import com.fh.common.api.vo.Result;
import com.fh.modules.kms.entity.SqlLog;
import com.fh.modules.kms.service.SqlLogService;
import com.fh.modules.kms.vo.SqlLogVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author qiujunda
 * @Date 15/06/2020
 * @Description
 */
@Log4j2
//@RestController
//@RequestMapping("/fherp/sqlLog")
public class SqlLogController {
    @Autowired
    private SqlLogService sqlLogService;

    @PostMapping("/add")
    @ApiOperation("新增")
    public Result addSqlLog(@RequestBody SqlLogVo sqlLogVo){
        String indexName=sqlLogVo.getIndexName();
        SqlLog sqlLog=sqlLogVo.getSqlLog();
        sqlLog.setId(System.currentTimeMillis());
        sqlLog.setDbName(indexName);
        sqlLogService.save(sqlLog);

//        ((EsAttribute)SpringContextUtils.getBean("esAttribute")).setIndexName(indexName);

//        sqlLog.setRequestBeginTime(new Date());
//        sqlLog.setRequestEndTime(new Date());

        return Result.ok("新增成功");
    }

    @PostMapping("/query")
    @ApiOperation("查询")
    public Result querySqlLog(@RequestBody  SqlLogVo sqlLogVo){
        Object o=sqlLogService.queryForPage(sqlLogVo);
        return Result.ok(o);
    }
}
